public class Test {
    public int singleNumber1(int[] nums) {
        int ans = 0;
        for(int x : nums) {
            ans ^= x;
        }
        return ans;
    }

    public int[] singleNumber2(int[] nums) {
        int sum = 0;
        for(int x : nums) {
            sum ^= x;
        }

        sum &= -sum;
        int ret1 = 0, ret2 = 0;
        for(int x : nums) {
            if((x & sum) == 0) {
                ret1 ^= x;
            } else {
                ret2 ^= x;
            }
        }

        return new int[]{ret1,ret2};
    }

    public int hammingWeight(int n) {
        int count = 0;
        while(n != 0) {
            n &= (n-1);
            count++;
        }
        return count;
    }


    public static void main(String[] args) {

    }
}
